package com.doumuxie.frame;

import com.doumuxie.linstener.MainListener;

import javax.swing.*;
import java.awt.*;

/**
 * @author doumuxie https://gitee.com/doumuxie/
 * @version 1.0
 * @date 2020/9/26 9:03
 * @description 主窗口
 **/
public class MainFrame extends JFrame {

    private static final long serialVersionUID = 1L;

    private JMenuBar mBar;
    // 文件
    private JMenu fileMenu;
    // 编辑
    private JMenu editMenu;
    // 进程管理
    private JMenu processMenu;
    // 存储管理
    private JMenu stroageMenu;
    // 设备管理
    private JMenu driverMenu;
    // 打开 关闭 退出按钮
    private JMenuItem miOpen, miSave, miExit;
    // 进程状态转换 生产者消费者 进程调度 银行家算法 按钮
    private JMenuItem pChange, pConsume, pProcess, pBank;
    // 动态分区算法 页面置换算法算法
    private JMenuItem sDeny, sChange;
    // 禁止 运行编辑
    private JMenuItem editAllow, editDeny;

    // 工具条
    private JToolBar jtb;
    // 工具条 打开 关闭 退出按钮
    private JButton jtbOpen;
    private JButton jtbSave;
    private JButton jtbExit;

    private JTextArea textArea;

    public MainFrame() {
        super("操作系统辅助教学系统");
        this.setSize(600, 500);

        // 面板挂菜单栏
        mBar = new JMenuBar();
        // container.add(mBar);//awt的方式
        setJMenuBar(mBar);

        // 菜单栏挂菜单
        fileMenu = new JMenu("文件(F)");
        editMenu = new JMenu("编辑(E)");
        processMenu = new JMenu("进程管理(P)");
        stroageMenu = new JMenu("存储管理(M)");
        driverMenu = new JMenu("设备管理(D)");
        mBar.add(fileMenu);
        mBar.add(editMenu);
        mBar.add(processMenu);
        mBar.add(stroageMenu);
        mBar.add(driverMenu);

        // 文件子菜单
        miOpen = new JMenuItem("打开");
        miSave = new JMenuItem("保存");
        miExit = new JMenuItem("退出");

        fileMenu.add(miOpen);
        fileMenu.add(miSave);
        fileMenu.addSeparator();// 分隔条
        fileMenu.add(miExit);
        // 编辑子菜单
        editAllow = new JMenuItem("允许编辑");
        editDeny = new JMenuItem("禁止编辑");

        editMenu.add(editAllow);
        editMenu.add(editDeny);

        editAllow.addActionListener(new MainListener(this));
        editDeny.addActionListener(new MainListener(this));

        // 进程管理子菜单
        pChange = new JMenuItem("进程状态转换");
        pConsume = new JMenuItem("生产者-消费者");
        pProcess = new JMenuItem("进程调度");
        pBank = new JMenuItem("银行家算法");

        processMenu.add(pChange);
        processMenu.add(pConsume);
        processMenu.add(pProcess);
        processMenu.add(pBank);

        // 存储管理子菜单
        sDeny = new JMenuItem("动态分区分配算法");
        sChange = new JMenuItem("页面置换算法");

        stroageMenu.add(sDeny);
        stroageMenu.add(sChange);

        // 工具条
        jtb = new JToolBar();
        Icon open = new ImageIcon("images/打开.png");
        Icon save = new ImageIcon("images/保存.png");
        Icon exit = new ImageIcon("images/退出.png");

        jtbOpen = new JButton("打开");
        jtbOpen.setIcon(open);
        jtbSave = new JButton("保存");
        jtbSave.setIcon(save);
        jtbExit = new JButton("退出");
        jtbExit.setIcon(exit);

        jtb.add(jtbOpen);
        jtb.add(jtbSave);
        jtb.add(jtbExit);

        // 添加工具条
        this.add(jtb, BorderLayout.NORTH);

        // 文本域
        textArea = new JTextArea();
        // 加入滚动条
        JScrollPane jsp = new JScrollPane(textArea);
        jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        this.add(jsp, BorderLayout.CENTER);

        // 添加事件
        miOpen.addActionListener(new MainListener(this));
        jtbOpen.addActionListener(new MainListener(this));
        miExit.addActionListener(new MainListener(this));
        jtbExit.addActionListener(new MainListener(this));
        jtbSave.addActionListener(new MainListener(this));
        miSave.addActionListener(new MainListener(this));
        pChange.addActionListener(new MainListener(this));

        pConsume.addActionListener(new MainListener(this));

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    public JMenuBar getmBar() {
        return mBar;
    }

    public void setmBar(JMenuBar mBar) {
        this.mBar = mBar;
    }

    public JMenu getFileMenu() {
        return fileMenu;
    }

    public void setFileMenu(JMenu fileMenu) {
        this.fileMenu = fileMenu;
    }

    public JMenu getEditMenu() {
        return editMenu;
    }

    public void setEditMenu(JMenu editMenu) {
        this.editMenu = editMenu;
    }

    public JMenu getProcessMenu() {
        return processMenu;
    }

    public void setProcessMenu(JMenu processMenu) {
        this.processMenu = processMenu;
    }

    public JMenu getStroageMenu() {
        return stroageMenu;
    }

    public void setStroageMenu(JMenu stroageMenu) {
        this.stroageMenu = stroageMenu;
    }

    public JMenu getDriverMenu() {
        return driverMenu;
    }

    public void setDriverMenu(JMenu driverMenu) {
        this.driverMenu = driverMenu;
    }

    public JMenuItem getMiOpen() {
        return miOpen;
    }

    public void setMiOpen(JMenuItem miOpen) {
        this.miOpen = miOpen;
    }

    public JMenuItem getMiSave() {
        return miSave;
    }

    public void setMiSave(JMenuItem miSave) {
        this.miSave = miSave;
    }

    public JMenuItem getMiExit() {
        return miExit;
    }

    public void setMiExit(JMenuItem miExit) {
        this.miExit = miExit;
    }

    public JMenuItem getpChange() {
        return pChange;
    }

    public void setpChange(JMenuItem pChange) {
        this.pChange = pChange;
    }

    public JMenuItem getpConsume() {
        return pConsume;
    }

    public void setpConsume(JMenuItem pConsume) {
        this.pConsume = pConsume;
    }

    public JMenuItem getpProcess() {
        return pProcess;
    }

    public void setpProcess(JMenuItem pProcess) {
        this.pProcess = pProcess;
    }

    public JMenuItem getpBank() {
        return pBank;
    }

    public void setpBank(JMenuItem pBank) {
        this.pBank = pBank;
    }

    public JMenuItem getsDeny() {
        return sDeny;
    }

    public void setsDeny(JMenuItem sDeny) {
        this.sDeny = sDeny;
    }

    public JMenuItem getsChange() {
        return sChange;
    }

    public void setsChange(JMenuItem sChange) {
        this.sChange = sChange;
    }

    public JMenuItem getEditAllow() {
        return editAllow;
    }

    public void setEditAllow(JMenuItem editAllow) {
        this.editAllow = editAllow;
    }

    public JMenuItem getEditDeny() {
        return editDeny;
    }

    public void setEditDeny(JMenuItem editDeny) {
        this.editDeny = editDeny;
    }

    public JToolBar getJtb() {
        return jtb;
    }

    public void setJtb(JToolBar jtb) {
        this.jtb = jtb;
    }

    public JButton getJtbOpen() {
        return jtbOpen;
    }

    public void setJtbOpen(JButton jtbOpen) {
        this.jtbOpen = jtbOpen;
    }

    public JButton getJtbSave() {
        return jtbSave;
    }

    public void setJtbSave(JButton jtbSave) {
        this.jtbSave = jtbSave;
    }

    public JButton getJtbExit() {
        return jtbExit;
    }

    public void setJtbExit(JButton jtbExit) {
        this.jtbExit = jtbExit;
    }

    public JTextArea getTextArea() {
        return textArea;
    }

    public void setTextArea(JTextArea textArea) {
        this.textArea = textArea;
    }


}
